package cn.com.bluemoon.daps.system.service.impl;

import cn.com.bluemoon.daps.api.standard.RemoteStandardDimService;
import cn.com.bluemoon.daps.api.standard.RemoteStandardIndexService;
import cn.com.bluemoon.daps.system.service.BizLineDeletePredicate;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

/**
 * 判断标准是否引用改业务线
 *
 * @author Jarod.Kong
 */
//@Service
@Slf4j
public class StandardModuleBizLineDeletePredicate implements BizLineDeletePredicate {
    @Lazy
    @Autowired
    private RemoteStandardIndexService standardIndexService;

    @Lazy
    @Autowired
    private RemoteStandardDimService dimService;

    @Override
    public Result<Integer> predicate(Integer bizLineId) {
        checkPredicate(bizLineId);
        if (standardIndexService.relatedBizLineId(bizLineId).getContent()) {
            return Result.<Integer>builder().canDelete(false).key(bizLineId).message("数据标准-指标标准已引用，不可删除").build();
        }
        // 维度关联
        if (dimService.relatedBizLineId(bizLineId).getContent()) {
            return Result.<Integer>builder().canDelete(false).key(bizLineId).message("数据标准-维度中已引用，不可删除").build();
        }
        return Result.<Integer>builder().canDelete(true).key(bizLineId).build();
    }
}
